package laugh.listener;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import laugh.util.Constants;

/**
 * 
*    
* 项目名称：LaughFactory   
* 类名称：TimerListner   
* 类描述：  随tomcat启动的定时任务，定时刷新内容积分
* 创建人：wizard   
* 创建时间：2012-3-30 下午03:12:21   
* 修改人：wizard   
* 修改时间：2012-3-30 下午03:12:21   
* 修改备注：   
* @version 0.9
*
 */
public class TimerListner implements ServletContextListener {

    private Timer timer;

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        if (timer != null) {
            timer.cancel();
            event.getServletContext().log("定时器已销毁");
        }
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        timer = new Timer(true);
        event.getServletContext().log("定时器已启动");
        timer.schedule(new ScoreRefreshTask(event.getServletContext()), 0,
                Constants.SCORE_COUNT_FREQUENCY);
        event.getServletContext().log("已添加任务");
    }

}
